package com.dgw.controller;

import com.dgw.exceptions.UserNotFoundExits;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.ViewResolver;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.Map;
import java.util.Random;

/**
 * @program: spring-boot-web-restfulcrud
 * @description:
 * @author: Mr.Dai
 * @create: 2019-11-27 19:53
 **/
@RestController
//@ApiIgnore
public class HelloController {

    /*@GetMapping("/test")
    public ModelAndView index(){
        return  new ModelAndView("test");
    }*/

    @GetMapping("/testerror")
    public ModelAndView testError(){
           if(true){
               throw new UserNotFoundExits();
           }
       return new ModelAndView("/index");
    }

    @GetMapping("/hello")
    public ModelAndView hello(ModelAndView modelAndView){
            modelAndView.addObject("hello","<h1>你好<h1>");
            modelAndView.setViewName("success");
            return modelAndView;
    }

    @RequestMapping(value = "/randData",method = RequestMethod.GET)
    public ModelAndView randData(){
        ArrayList<String> lists = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            lists.add("tom"+new Random().nextInt());
        }
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("success");
        modelAndView.addObject("data",lists);
        return modelAndView;
    }
}
